<form action="index.php?<{$env.server.QUERY_STRING}>" method="post" id="member-edit-form">
  <div class="tableform">
    <input type=hidden name='member_id' value=<{$mem.member_id}>>
    <div class="division" style="border:none;">
      <table class="forform" width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>  <th><{t}>用户名<{/t}></th>
          <td> <{if $mem.account.local}><{$mem.account.local}><{elseif $mem.account.email}><{$mem.account.email}><{else}><{$mem.account.mobile}><{/if}></td>
        </tr>
        <tr>
          <th><{t}>邮箱<{/t}></th>
          <td>
		    <{if $mem.account.email}>
				<{$mem.account.email}>
			<{elseif $mem.members.email}>
				<{$mem.members.email}>
			<{else}>
			    <{input type="email" signup_type="email" autocomplete="off" name="contact[email]" class="action-account-check text" vtype="required" value="" placeholder=$___b2c="请填写邮箱"|t:'b2c' id="email"}><span  style="color:red" class="validation-messagebox" id="emailid"></span>
			<{/if}>
          </td>
        </tr>
        <tr>
          <th><{t}>手机号码<{/t}></th>
          <td>
		    <{if $mem.account.mobile}>
				<{$mem.account.phone_setting}>&nbsp;<{$mem.account.mobile}>
			<{elseif $mem.members.mobile}>
			    <{$mem.members.phone_setting}>&nbsp;<{$mem.members.mobile}>
            <{else}>
				<select name="phone_setting" id="quhao">
					<{foreach from=$phones item=items}>
					<option sid="<{$items.length}>" value="<{$items.area}>" <{if $mem.members.phone_setting && $items.area == $mem.members.phone_setting}> selected <{/if}>><{$items.country}><{$items.area}></option>
					<{/foreach}>
				</select>
				<{input type="text" name="contact[phone][mobile]" value=$mem.members.mobile autocomplete="off" placeholder=$___b2c="请填写手机号"|t:'b2c' vtype="required" id="check_tel"}><span  style="color:red" class="validation-messagebox" id="phoneid"></span>
			<{/if}>
          </td>
        </tr>
		<tr>
          <th><{t}>姓名<{/t}></th>
          <td>
            <{input type="text" name="name" size="20" vtype="required" value=$mem.members.name}>
          </td>
        </tr>
        <tr>  <th><{t}>会员等级<{/t}></th>
          <td> <{input type='select' name='member_lv[member_group_id]' options=$mem.lv.options required=true value=$mem.lv.value }>  <span onclick="new Dialog('index.php?app=b2c&ctl=admin_member&act=chkpassword&p[0]=<{$member_id}>',{width:400,height:300,title:'<{t}>修改密码<{/t}>'})" class="lnk">[<{t}>修改密码<{/t}>]</span> </td>
        </tr>
        <{foreach from=$attr item=item name="item" key='row'}>
        <tr>
          <th><{if $item.attr_required eq 'true'}><em>*</em><{/if}><{$item.attr_name|t:'b2c'}></th>
         <td>  

            <{if $item.attr_type =='date'}> 
            <{if $item.attr_value != '0-0-0' && $item.attr_value != '--'}>
            <{if $item.attr_required eq 'true'}>
            <{input class="cal" type='date' vtype="required&&date" name=$item.attr_column value=$item.attr_value}>
            <{else}>
            <{input class="cal" type='date' name=$item.attr_column value=$item.attr_value}>
            <{/if}>
            <{else}>
            <{if $item.attr_required eq 'true'}>
            <{input class="cal" type="date" vtype="required&&date" name=$item.attr_column}>
            <{else}>
            <{input class="cal" type="date" name=$item.attr_column}>
            <{/if}>
            <{/if}>
            <{/if}>

            <{if $item.attr_type =='region'}>
            <{if $item.attr_required eq 'true'}>
            <{input app=ectools type="region" name=$item.attr_column value=$item.attr_value vtype="area" }>
            <{else}>
            <{input app=ectools type="region" name=$item.attr_column value=$item.attr_value vtype="" }>
            <{/if}>
            <{/if}>

            <{if $item.attr_type =='gender'}>
            <{input type='gender' name=$item.attr_column value=$item.attr_value }>
            <{/if}>

            <{if $item.attr_type =='select'}>
            <select name='<{$item.attr_column}>' <{if $item.attr_required eq 'true'}>class='_x_ipt' vtype='required'<{/if}>>
              <option value='' <{if $item.attr_value == ''}>selected='true'<{/if}>><{t}>请选择<{/t}></option>
              <{foreach from=$item.attr_option item=option name="option"}>
              <option value='<{$option}>' <{if $item.attr_value == $option}>selected='true'<{/if}>><{$option}></option>
              <{/foreach}>

            </select>
            <{/if}>

            <{if $item.attr_type =='checkbox'}>
            <{foreach from=$item.attr_option item=checkbox name="checkbox" }>



            <input type='checkbox' name=box:<{$item.attr_column}>[]" value='<{$checkbox}>' <{foreach from=$item.attr_value item=checkboxvalue name="checkboxvalue" }>
            <{if $checkboxvalue==$checkbox}>
            checked ='true' 
            <{/if}>
            <{/foreach}>><label><{$checkbox}></label><br/>
            <{/foreach}><input type='hidden' name='<{$item.attr_column}>[]' value='%no%'>

            <{if $item.attr_required eq 'true'}><input type='hidden' class='_x_ipt' vtype='selectc'/>
            <{/if}>
            <{/if}>


            <{if $item.attr_type == 'text'}>
            <input type='text' name=<{$item.attr_column}> value='<{$item.attr_value}>' vtype='<{if $item.attr_required eq 'true'}>required&&<{/if}><{$item.attr_valtype}>' />
            <{/if}>

            <{if $item.attr_type == 'number'}>
            <input type='text' name=<{$item.attr_column}> value='<{$item.attr_value}>' vtype='<{if $item.attr_required eq 'true'}>required&&<{/if}><{$item.attr_valtype}>' />
            <{/if}>

            <{if $item.attr_type == 'alpha'}>
            <input type='text' name=<{$item.attr_column}> value='<{$item.attr_value}>' vtype='<{if $item.attr_required eq 'true'}>required&&<{/if}><{$item.attr_valtype}>' />
            <{/if}>

          </td>
        </tr>
        <{/foreach}>  
        <tr>
          <th></th>

        </tr>
      </table>
    </div>
    <div class="table-action"><{button type="submit" label=$___b2c="保存"|t:'b2c' id="member-edit-form-submit"}></div>
  </div>
</form>

<script>
  (function(){
    //手机验证 by yyj 2016/1/27
	if($("check_tel")){
	    $("check_tel").addEvent('blur',function(){
			var str = this.get('value').trim();
			var obj = $$("#quhao option:selected");
			var num = obj[0].get('sid');
			var reg = new RegExp("^[1-9]\\d{"+(num-1)+"}$");
			
			if(str.length!=0){
				if(!reg.test(str)){
					$("phoneid").set('html','<{t}>手机格式错误<{/t}>');
				}else{
					$("phoneid").set('html','');
				}
			}
		});
		$('member-edit-form-submit').addEvent('click',function(e){
			var str = $("check_tel").get('value').trim();
			var obj = $$("#quhao option:selected");
			var num = obj[0].get('sid');
			var reg = new RegExp("^[1-9]\\d{"+(num-1)+"}$");
			
			if(str.length!=0){
				if(!reg.test(str)){
					$("phoneid").set('html','<{t}>手机格式错误<{/t}>');
					e.stop();
				}
			}
		});
	}
    //邮箱验证 by yyj 2016/1/28
	if($("email")){
	    $("email").addEvent('blur',function(){
			var email = this.get('value').trim();
			if(!email || email && !email.test(/\S+@\S+/)){
				$('emailid').set('html','<{t}>请填写正确的邮箱地址<{/t}>');
			}else{
				$('emailid').set('html','');
			}
		});
		$('member-edit-form-submit').addEvent('click',function(e){
			var email = $("email").get('value').trim();

			if(!email || email && !email.test(/\S+@\S+/)){
				$("emailid").set('html','<{t}>请填写正确的邮箱地址<{/t}>');
				e.stop();
			}
		});
	}

    var input = $(document.body).getElements('input[name=contact[area]]')[0];
    var select = input.getNext('select');
    if(input.getParent('span').get('vtype') == 'area') {
      return;
    }
    select.addEvent('change',function(e){
      if(!e.target) return;
      if($(e.target).value !='_NULL_'){
        input.getParent('span').set('vtype','area');
      }
      else{
        input.getParent('span').set('vtype','');
      }
    });
    
  })();
</script>
